//
//  CollectionVC.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/29.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "CollectionVC.h"

#import "CellOfOnePic.h"

#import "DBHandler.h"

#import "VcOfWebView.h"

#import <WebKit/WebKit.h>
@interface CollectionVC ()
@property(nonatomic, retain)NSString *strOfPath;

@property(nonatomic, retain)NSMutableDictionary *mDic;
@property(nonatomic, retain)NSMutableArray *mArrOfColletion;


@end

@implementation CollectionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:248.0 / 256.0f green:239.0 / 256.0f blue:239.0 / 256.0f alpha:1];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[CellOfOnePic class] forCellReuseIdentifier:@"pool"];
    self.navigationItem.title = @"我的收藏";
    [[DBHandler sharedDBHandle]openDB];
    /*目录搜索路径列表*/
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    /*表格路径*/
    NSString *documentsDirectory = [[paths objectAtIndex:0]stringByAppendingString:@"Collection.db"];
    NSLog(@"%@", documentsDirectory);
    self.strOfPath = documentsDirectory;
    /**/
    self.mDic = [[NSMutableDictionary alloc]initWithContentsOfFile:self.strOfPath].mutableCopy;
    
    self.mArrOfColletion = [[DBHandler sharedDBHandle]getData].mutableCopy;
    
    [self.mDic release];

}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    [[DBHandler sharedDBHandle] openDB];
    
    [[DBHandler sharedDBHandle] createTable];
    NewModel *model = [self.mArrOfColletion objectAtIndex:indexPath.row];
    
    VcOfWebView *vc = [[VcOfWebView alloc]init];
    
    WKWebView *web = [[WKWebView alloc]initWithFrame:vc.view.frame];
    web.frame = CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT);
    
    [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:model.mob_h5_url]]];
    
    
    [self.navigationController pushViewController:vc animated:YES];
    
    [vc.view addSubview:web];
    [vc release];
    [web release];
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat
{
    CellOfOnePic *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    
    cell.NewModel = self.mArrOfColletion[indexPat.row];
    
    
    return cell;
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 150;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mArrOfColletion.count;
}


- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    [self.tableView setEditing:editing animated:animated];
}


- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
